//
//  DDMainVC.m
//  SinaMicroBlogOC
//
//  Created by dqw on 15/7/29.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "DDMainVC.h"
#import "DDHomeVC.h"
#import "DDDiscoveryVC.h"
#import "DDMessageVC.h"
#import "DDProfileVC.h"



@interface DDMainVC ()

@end

@implementation DDMainVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewDidLayoutSubviews
{
    CGFloat W = self.tabBar.bounds.size.width / self.viewControllers.count;
    UIButton *button = [self loadCenterButton];
    button.frame = CGRectMake(2 * W, 0, W, self.tabBar.bounds.size.height);
}
- (UIButton *)loadCenterButton{
    UIButton *button = [[UIButton alloc]init];
    [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    [self.tabBar addSubview:button];
    return button;
}
- (void)addChildVCs
{
    [self addChildVCWithVC:[[DDHomeVC alloc]init] title:@"首页" imgName:@"tabbar_home"];
    [self addChildVCWithVC:[[DDDiscoveryVC alloc]init] title:@"发现" imgName:@"tabbar_message_center"];
    [self addChildViewController:[[UIViewController alloc]init]];
    [self addChildVCWithVC:[[DDMessageVC alloc]init] title:@"信息" imgName:@"tabbar_discover"];
    [self addChildVCWithVC:[[DDProfileVC alloc]init] title:@"我" imgName:@"tabbar_profile"];
     
    
}
- (void)addChildVCWithVC:(UIViewController *)VC title:(NSString *)title imgName:(NSString *)imgName
{
    
    VC.title = title;
    VC.tabBarItem.image = [UIImage imageNamed:imgName];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:VC];
    [self addChildViewController:nav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
